<?php

namespace App\Modules\Admin\Repositories\Impl;

use App\Models\Activity;
use App\Modules\Admin\Repositories\Contracts\ActivityRepository;
use App\Modules\Admin\Repositories\Transformers\ActivityListTransformer;
use App\Repositories\Transformers\ActivityTransformer;

class ActivityRepositoryImpl implements ActivityRepository
{
    public function paginate($perPage, $filter)
    {
        $activity = Activity::where($filter)->orderBy('created_at', 'desc')->paginate($perPage);
        $result = fractal($activity, new ActivityListTransformer());

        return $result->toArray();
    }

    public function getAllActivityName()
    {
        $activity = Activity::get(['id', 'title']);
        return $activity;
    }

    public function find($id, $columns = ['*'])
    {
        $activity = Activity::find($id, $columns);

        $result = fractal($activity, new ActivityTransformer());

        return $result->toArray();

    }

    public function findByFilter($filter, $columns = ['*'])
    {
        return Activity::where($filter)->first($columns);
    }

    public function store($data)
    {
        return Activity::create($data);
    }

    public function update($data, $id)
    {
        return Activity::whereId($id)->update($data);
    }

    public function updateByFilter($data, $where)
    {
        return Activity::where($where)->update($data);
    }

    public function delete($id)
    {
        return Activity::whereId($id)->delete();
    }
}
